<?php
echo $javascript->link('ckeditor/ckeditor');
//$config['toolbar'] = array( 
//    array( 'Bold', 'Italic', 'Underline', 'Strike' ), 
//    array( 'Image', 'Link', 'Unlink', 'Anchor' ) 
//); 
$config['height'] = 800;
?>

<?php
echo $javascript->codeBlock("	
	function autoselect_types(){
		// click chackbox events
 		$( '#selectAllTypes').unbind('click').bind('click', function(){
 			if($(this).attr('checked')){
				$('.selectedTypes').attr('checked',true);
				$('.selectedTypes').attr('value',1);
			}else{
				$('.selectedTypes').attr('checked',false);
				$('.selectedTypes').attr('value',0);
			}
		});
		
		$( '#inputAllInventory').unbind('keyup').bind('keyup', function(){
				$('.selectedInventory').attr('value',$(this).attr('value'));
		});	
	}
	
	$(document).ready(function(){
		autoselect_types();
	});	
",$options = array('allowCache'=>false,'safe'=>false,'inline'=>false));
?>

<div class="storeProducts form">
<?php echo $cksource->create(__("StoreProduct",true),array('url'=>array('plugin'=>'store','controller'=>'products','action'=>'add'),'type' => 'file'));?>
	<fieldset>
 		<legend><?php __d('store','Add Store Product'); ?></legend>
		<table width="100%" cellpadding="10" cellspacing="0">
			<tr>
				<td width="40%" valign="top">
				<?php					
					echo $this->Form->input('name',array('class'=>'_100'));
					echo $this->Form->input('serial_number',array('class'=>'_50'));
					echo $this->Form->input('price_detaliczna',array('label'=>__d('store','Price',true),'value'=>'0.0'));
//					echo $this->Form->input('price_przecena');
					echo $this->Form->input('price_promocja',array('label'=>__d('store','Price - Special Offer',true)));
					echo $this->Form->input('currency_id',array('options'=>$storeCurrencies,'selected'=>$this->Session->read('Store.default_currency')));
					echo $this->Form->input('www',array('class'=>'_100'));
//					echo $this->Form->input('tax_id',array('options'=>$storeTaxes,'empty'=>''));
//					echo $this->Form->input('unit_id',array('options'=>$storeUnits,'empty'=>''));	
					echo $this->Form->input('active');	

				?>
				</td>
				<td width="30%" valign="top">
					<?php
						echo $this->Form->input('group_id',array('label'=>__d('store','Homepage Display',true),'options'=>$storeGroups,'empty'=>''));
						echo $this->Form->input('StoreUpload.0.file', array('type' => 'file','label'=>__d("store","Main Icon Store Product",true)));							
					?>
				</td>
				<td width="30%" valign="top" rowspan="3">
					<?php 
						echo $this->Form->input('StoreProductCategory.category_id',
							array('options'=>$parentCategories,'empty'=>array(''=>'')));
						$this->Js->get('#StoreProductCategoryCategoryId')->event('change', $this->Js->request( 
							array('plugin'=>'store','controller'=>'products','action'=>'product_types'),
							array( 
								'dataExpression' => true,
								'update'=>'#selectProductTypes',
								'data'=>'{category_id:$(\'#StoreProductCategoryCategoryId\').val()}',
								'before'=>'$(\'#selectProductTypes\').html("<tr><td>'.__d('store','reading data, please wait ...',true).'</td></tr>")',
								'complete'=>'autoselect_types();'
							))									
						);
					?>
					<div id="selectProductTypes">
						<?php

							echo $this->Form->input('StoreModel.StoreModel',array('label'=>__d('store','Offer Type',true),'options'=>$storeModels,'empty'=>'','class'=>'_100'));	
						?>
						<table class="index" cellpadding="0" cellspacing="0">
							<tr>
								<th>
									<input type="checkbox" id="selectAllTypes">
								</th>
								<th>
									<?php echo __d("store","Name",true)?>
								</th>
								<th>
									<div class="input text"><input type="text" size="2" id="inputAllInventory"></div>
								</th>
								<th>
									<?php echo __d("store","For",true)?>
								</th>
							</tr>
							<tr>
								<td valign="middle" align="center">								
									<?php echo $this->Form->checkbox("StoreProduct.service", array('label'=>false,'after'=>false  ));?>
								</td>
								<td valign="middle" colspan="3">
									<?php echo __('Serice',true)?>
								</td>
							
							</tr>					
							<?php 
							$i = 0;
							foreach ($storeTypes as $key => $type) { 
								$type_id = $type['StoreType']['id'];
								$default_group = $type['StoreType']['default_group_id'];
								$name = $type['StoreType']['name'];
								$class = null;
								if ($i++ % 2 == 0) {
									$class = ' class="altrow"';
								}	
							?>
							<tr <?php echo $class;?>>
								<td valign="middle" align="center">								
									<?php echo $this->Form->checkbox("StoreType.type_id.{$type_id}", array('label'=>false,'after'=>false,'class'=>'selectedTypes' ));?>
								</td>
								<td valign="middle">
									<?php echo $name?>
								</td>
								<td valign="middle">
									<?php echo $this->Form->input("StoreType.inventory.{$type_id}",array('label'=>false,'size'=>2,'class'=>'selectedInventory'));?>
								</td>
								<td class="last" valign="middle">
									<?php echo $this->Form->input("StoreType.for_group.{$type_id}",array('label'=>false,'options'=>$storeTypeGroup,'empty'=>'','selected'=>$default_group,'hiddenField'=>false,'style'=>'width: 110px;'))?>
								</td>
							</tr>
							<?php }?>
							
						</table>
					</div>				
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<?php echo $cksource->ckeditor('content', array( 'config'=>$config));?>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<?php echo $this->Form->input('keywords',array('class'=>'_100'));	?>
				</td>
			</tr>
		</table>
	</fieldset>
<?php echo $this->Form->end(__d('store','Submit', true));?>


</div>

<?php if($session->check('Auth.User.id')){?>
<?php echo $this->element('toolbar_actions_main',array('plugin'=>'store','toolbar'=>'product'))?>
<?php }?>